package com.power.controller;

import com.alibaba.fastjson.JSONObject;
import com.power.ov.ResultData;
import com.power.pojo.SovlePojo;
import com.power.service.SovleQueryService;
import com.power.service.impl.SovleQueryServiceImpl;
import com.power.utils.WriterUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * Created with IntelliJ IDEA.
 * User: 朱雄
 * Date: 2020/10/10 10:59
 * Description:
 * Version: V1.0
 */
@WebServlet("/querySovle.do")
public class SovleQueryController extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String string=req.getParameter("data");
        int page = Integer.parseInt(req.getParameter("page"));
        int limit = Integer.parseInt(req.getParameter("limit"));
        SovleQueryService service=new SovleQueryServiceImpl();
        SovlePojo sovlePojo =JSONObject.parseObject(string, SovlePojo.class);
        ResultData resultData=null;
        try {
            resultData=service.sovleQueryByAll(sovlePojo,page,limit);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        WriterUtil.getWriter(resp,resultData);
    }
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String page=req.getParameter("page");
        String limit=req.getParameter("limit");
        SovleQueryService service=new SovleQueryServiceImpl();
        ResultData resultData=new ResultData();
        try {
            resultData=service.sovleQueryAll(page,limit);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        WriterUtil.getWriter(resp,resultData);
    }

}
